<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="98px">
      <el-form-item label="订单编号" prop="orderCode">
        <el-input v-model="queryParams.orderCode" placeholder="请输入订单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="订单类型" prop="orderType">
        <el-select v-model="queryParams.orderType" placeholder="请选择订单类型" clearable>
          <el-option v-for="dict in dict.type.mes_order_type" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="客户ID" prop="clientId">
        <el-input v-model="queryParams.clientId" placeholder="请输入客户ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="客户编码" prop="clientCode">
        <el-input v-model="queryParams.clientCode" placeholder="请输入客户编码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="客户名称" prop="clientName">
        <el-input v-model="queryParams.clientName" placeholder="请输入客户名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="产品分类" prop="itemTypeId">
        <el-select v-model="queryParams.itemTypeId" placeholder="请选择产品分类">
          <el-option v-for="item in itemTypeList" :key="item.itemTypeId" :label="item.itemTypeName"
            :value="item.itemTypeId">
          </el-option>
        </el-select>
        <!-- <el-input v-model="queryParams.itemTypeId" placeholder="请输入产品分类ID" clearable
          @keyup.enter.native="handleQuery" /> -->
      </el-form-item>
      <!-- <el-form-item label="产品ID" prop="productId">
        <el-input v-model="queryParams.productId" placeholder="请输入产品ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="产品编号" prop="productCode">
        <el-input v-model="queryParams.productCode" placeholder="请输入产品编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="订单数量" prop="orderCount">
        <el-input v-model="queryParams.orderCount" placeholder="请输入订单数量" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="库存数量" prop="stockCount">
        <el-input v-model="queryParams.stockCount" placeholder="请输入库存数量" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="投产数量" prop="quantity">
        <el-input v-model="queryParams.quantity" placeholder="请输入投产数量" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="评审类型" prop="reviewType">
        <el-select v-model="queryParams.reviewType" placeholder="请选择评审类型" clearable>
          <el-option v-for="dict in dict.type.mes_review_type" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="工艺路线ID" prop="routeId">
        <el-input v-model="queryParams.routeId" placeholder="请输入工艺路线ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="工艺路线编号" prop="routeCode">
        <el-input v-model="queryParams.routeCode" placeholder="请输入工艺路线编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="工艺路线名称" prop="routeName">
        <el-input v-model="queryParams.routeName" placeholder="请输入工艺路线名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="投料点" prop="feedingPoint">
        <el-input v-model="queryParams.feedingPoint" placeholder="请输入投料点" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="投料数量" prop="feedingCount">
        <el-input v-model="queryParams.feedingCount" placeholder="请输入投料数量" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="订单用纸" prop="paperAmount">
        <el-input v-model="queryParams.paperAmount" placeholder="请输入订单用纸" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="允许溢短数" prop="gapCount">
        <el-input v-model="queryParams.gapCount" placeholder="请输入允许溢短数" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="稿件类型" prop="manuscriptType">
        <el-select v-model="queryParams.manuscriptType" placeholder="请选择稿件类型" clearable>
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="执行标准" prop="standard">
        <el-input v-model="queryParams.standard" placeholder="请输入执行标准" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="订单成本" prop="cost">
        <el-input v-model="queryParams.cost" placeholder="请输入订单成本" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="价格" prop="price">
        <el-input v-model="queryParams.price" placeholder="请输入价格" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="订单描述" prop="orderRemark">
        <el-input v-model="queryParams.orderRemark" placeholder="请输入订单描述" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="业务备注" prop="businessRemark">
        <el-input v-model="queryParams.businessRemark" placeholder="请输入业务备注" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="订单状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择订单状态" clearable>
          <el-option v-for="dict in dict.type.mes_md_order_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="优先级" prop="priority">
        <el-input v-model="queryParams.priority" placeholder="请输入优先级" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="箱子资料" prop="boxInfo">
        <el-input v-model="queryParams.boxInfo" placeholder="请输入箱子资料" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="开单人" prop="salesman">
        <el-input v-model="queryParams.salesman" placeholder="请输入开单人" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="预留字段1" prop="attr1">
        <el-input
          v-model="queryParams.attr1"
          placeholder="请输入预留字段1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="下单日期">
        <el-date-picker v-model="daterangeOrderDate" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="交货日期">
        <el-date-picker v-model="daterangeRequestDate" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
      <el-form-item><el-checkbox v-model="checked" @change="handleCheckboxChange">只看我的</el-checkbox></el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['mes:md:order:add']">新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['mes:md:order:edit']">修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['mes:md:order:remove']">删除</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-receiving" :disabled="single" size="mini"
          @click="handleOrderApproved" v-hasPermi="['mes:md:order:approved']">审核</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-receiving" :disabled="single" size="mini"
          @click="handleOrderStatus" v-hasPermi="['mes:md:order:reject']">驳回</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" :disabled="single"
          @click="handleExportReview" v-hasPermi="['mes:md:order:exportReview']">导出评审单</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['mes/md:order:export']">导出</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-select v-model="selectedColumns" size="mini" multiple @change="updateDisplayedColumns" placeholder="请选择展示列">
          <el-option
          v-for="column in availableColumns"
          :key="column.prop"
          :label="column.label"
          :value="column.prop"
          ></el-option>
        </el-select>
      </el-col> -->

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="订单ID" align="center" prop="orderId" /> -->
      <el-table-column label="订单编号" align="center" prop="orderCode" width="150" fixed>
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleView(scope.row)" v-hasPermi="['mes:md:order:query']">
            {{scope.row.orderCode}}</el-button>
        </template>
        <!-- <template slot-scope="scope">
          <router-link :to="'/mes/md/order/order-data/index/' + scope.row.orderId" class="link-type">
            <span>{{ scope.row.orderCode }}</span>
          </router-link> -->
        <!-- <el-link type="primary" :underline="false" @click="openView(scope.row)">{{scope.row.orderCode}}</el-link> -->
        <!-- </template> -->
      </el-table-column>
      <el-table-column label="订单类型" align="center" prop="orderType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_order_type" :value="scope.row.orderType" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="客户ID" align="center" prop="clientId" /> -->
      <el-table-column label="客户编码" align="center" prop="clientCode" width="120" />
      <el-table-column label="客户名称" align="center" prop="clientName" width="120" />
      <el-table-column label="产品分类" align="center" prop="itemTypeId" width="120">
        <template slot-scope="scope">
          <span>{{itemTypeName(scope.row.itemTypeId)}}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="产品ID" align="center" prop="productId" /> -->
      <el-table-column label="产品编号" align="center" prop="productCode" width="120" />
      <el-table-column label="产品名称" align="center" prop="productName" width="120" />
      <el-table-column label="下单日期" align="center" prop="orderDate" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="交货日期" align="center" prop="requestDate" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.requestDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="status" width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_md_order_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="订单数量" align="center" prop="orderCount" width="120" />
      <el-table-column label="库存数量" align="center" prop="stockCount" width="120" />
      <el-table-column label="投产数量" align="center" prop="quantity" width="120" />
      <el-table-column label="评审类型" align="center" prop="reviewType" width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_review_type" :value="scope.row.reviewType" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="工艺路线ID" align="center" prop="routeId" /> -->
      <!-- <el-table-column label="工艺路线编号" align="center" prop="routeCode" width="120" /> -->
      <!-- <el-table-column label="工艺路线名称" align="center" prop="routeName" width="120" /> -->
      <el-table-column label="投料点" align="center" prop="feedingPoint" width="120" />
      <el-table-column label="投料数量" align="center" prop="feedingCount" width="120" />
      <el-table-column label="订单用纸" align="center" prop="paperAmount" width="120" />
      <el-table-column label="允许溢短数" align="center" prop="gapCount" width="120" />
      <el-table-column label="稿件类型" align="center" prop="manuscriptType" width="120" />
      <el-table-column label="执行标准" align="center" prop="standard" width="120" />
      <!-- <el-table-column label="订单成本" align="center" prop="cost" /> -->
      <el-table-column label="价格" align="center" prop="price" width="120" />
      <el-table-column label="订单描述" align="center" prop="orderRemark" :show-overflow-tooltip="true" width="120" />
      <el-table-column label="业务备注" align="center" prop="businessRemark" :show-overflow-tooltip="true" width="120" />
      <el-table-column label="优先级" align="center" prop="priority" width="120" />
      <el-table-column label="箱子资料" align="center" prop="boxInfo" width="120" />
      <el-table-column label="开单人" align="center" prop="salesman" width="120" />
      <!-- <el-table-column label="预留字段1" align="center" prop="attr1" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit"
            v-if="scope.row.status == 'CREATE' && scope.row.createBy == userName" @click="handleUpdate(scope.row)"
            v-hasPermi="['mes:md:order:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete"
            v-if="scope.row.status == 'CREATE' && scope.row.createBy == userName" @click="handleDelete(scope.row)"
            v-hasPermi="['mes:md:order:remove']">删除</el-button>
          <el-button size="mini" type="text" icon="el-icon-receiving"
            v-if="scope.row.status == 'CREATE' && scope.row.salesmanId == userId" @click="handleOrderApproved(scope.row)"
            v-hasPermi="['mes:md:order:approved']">审核</el-button>
          <el-button size="mini" type="text" icon="el-icon-receiving"
            v-if="scope.row.status == 'SUBMIT'" @click="handleOrderStatus(scope.row, 'ENTER')"
            v-hasPermi="['mes:md:order:reject']">驳回</el-button>
          <el-button size="mini" type="text" icon="el-icon-receiving"
            v-if="scope.row.status == 'PRODUCTION'" @click="handleOrderStatus(scope.row, 'FINISH')"
            v-hasPermi="['mes:md:order:shutdown']">关单</el-button>
          <el-button size="mini" type="text" icon="el-icon-receiving"
            v-if="scope.row.status == 'FINISH'" @click="handleOrderStatus(scope.row, 'PRODUCTION')"
            v-hasPermi="['mes:md:order:restart']">重启</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handlePreview(scope.row.orderId)"
            >打印</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改业务订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body lock-scroll :modal="false" :fullscreen="true">
      <el-row v-if="viewType == 'ADD'" style="margin-bottom: 10px;">
        <el-select v-model="selectOrderId" filterable placeholder="历史订单导入" @change="fillForm">
          <el-option v-for="item in orderList" :key="item.orderId"
            :label="item.clientName + '-' + item.orderCode + '-' + item.productName + '-' + item.orderCount"
            :value="item.orderId">
          </el-option>
        </el-select>
      </el-row>
      <el-collapse v-model="activeNames" @change="">
        <el-collapse-item title="订单信息" name="1">
          <el-form ref="form" :inline="true" :model="form" :rules="rules" :disabled="viewType == 'VIEW'"
            label-width="120px">
            <el-form-item label="订单编号" prop="orderCode">
              <el-input v-model="form.orderCode" :disabled="viewType == 'UPDATE'" placeholder="请输入订单编号" />
            </el-form-item>
            <el-form-item label="订单类型" prop="orderType">
              <el-select v-model="form.orderType" placeholder="请选择订单类型">
                <el-option v-for="dict in dict.type.mes_order_type" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
            <!-- <el-form-item label="客户ID" prop="clientId">
              <el-input v-model="form.clientId" placeholder="请输入客户ID" />
            </el-form-item> -->
            <el-form-item label="客户编号" prop="clientCode">
              <el-input v-model="form.clientCode" style="width: 200px;" placeholder="请输入客户编号">
                <el-button slot="append" @click="handleSelectClient" icon="el-icon-search"></el-button>
              </el-input>
              <ClientSelect ref="clientSelect" @onSelected="onClientSelected"> </ClientSelect>
            </el-form-item>
            <el-form-item label="客户名称" prop="clientName">
              <el-input v-model="form.clientName" disabled placeholder="客户名称自动生成" />
            </el-form-item>
            <el-form-item label="产品分类" prop="itemTypeId">
              <el-select v-model="form.itemTypeId" :disabled="viewType == 'UPDATE'"
                @change="getRoutetypeListByItemTypeId" placeholder="请选择产品分类">
                <el-option v-for="item in itemTypeList" :key="item.itemTypeId" :label="item.itemTypeName"
                  :value="item.itemTypeId">
                </el-option>
              </el-select>
              <!-- <el-input v-model="form.itemTypeId" placeholder="请输入产品分类ID" /> -->
            </el-form-item>
            <!-- <el-form-item label="产品ID" prop="productId">
              <el-input v-model="form.productId" placeholder="请输入产品ID" />
            </el-form-item> -->
            <el-form-item label="产品编号" prop="productCode">
              <el-input v-model="form.productCode" style="width: 200px;" :disabled="viewType == 'UPDATE'"
                placeholder="请输入产品编号">
                <el-button slot="append" @click="handleSelectProduct" icon="el-icon-search"></el-button>
              </el-input>
              <ItemSelect ref="itemSelect" @onSelected="onItemSelected"> </ItemSelect>
            </el-form-item>
            <!-- <el-input v-model="form.productCode" :disabled="viewType == 'UPDATE'" placeholder="请输入产品编号" /> -->
<!--            </el-form-item>-->
            <el-form-item label="产品名称" prop="productName">
              <el-input v-model="form.productName" :disabled="viewType == 'UPDATE'" placeholder="请输入产品名称" />
            </el-form-item>
            <el-form-item label="下单日期" prop="orderDate">
              <el-date-picker clearable v-model="form.orderDate" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择下单日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="交货日期" prop="requestDate">
              <el-date-picker clearable v-model="form.requestDate" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择交货日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="评审类型" prop="reviewType">
              <el-select v-model="form.reviewType" clearable placeholder="请选择评审类型">
                <el-option v-for="dict in dict.type.mes_review_type" :key="dict.value" :label="dict.label"
                  :value="dict.value" />
              </el-select>
            </el-form-item>
            <!-- <el-form-item label="工艺路线ID" prop="routeId">
              <el-input v-model="form.routeId" placeholder="请输入工艺路线ID" />
            </el-form-item>
            <el-form-item label="工艺路线编号" prop="routeCode">
              <el-input v-model="form.routeCode" placeholder="请输入工艺路线编号" />
            </el-form-item>
            <el-form-item label="工艺路线名称" prop="routeName">
              <el-input v-model="form.routeName" placeholder="请输入工艺路线名称" />
            </el-form-item> -->
            <el-form-item label="订单数量(个)" prop="orderCount">
              <el-input-number v-model="form.orderCount" :min="0" :step="1" :max="999999" :precision="0" />
              <!-- <el-input v-model="form.orderCount" placeholder="请输入订单数量" /> -->
            </el-form-item>
            <el-form-item label="库存数量(个)" prop="stockCount">
              <el-input-number v-model="form.stockCount" :min="0" :step="1" :max="999999" :precision="0" />
              <!-- <el-input v-model="form.stockCount" placeholder="请输入库存数量" /> -->
            </el-form-item>
            <!-- <el-form-item label="投产数量(个)" prop="quantity">
              <el-input-number v-model="form.quantity" :min="0" :step="1" :max="999999" :precision="0" />
              <el-input v-model="form.quantity" placeholder="请输入投产数量" />
            </el-form-item> -->
            <el-form-item label="投料点(%)" prop="feedingPoint">
              <el-input-number v-model="form.feedingPoint" :min="0" :step="1" :max="999999" :precision="2" />
              <!-- <el-input v-model="form.feedingPoint" placeholder="请输入投料点" /> -->
            </el-form-item>
            <el-form-item label="投产数量(个)" prop="feedingCount">
              <el-input v-model="feedingCount" disabled placeholder="请输入投料数量" />
            </el-form-item>
            <el-form-item label="订单用纸(kg)" prop="paperAmount">
              <el-input v-model="paperAmount" placeholder="订单用纸自动生成" disabled />
            </el-form-item>
            <el-form-item label="允许溢短数(个)" prop="gapCount">
              <el-input-number v-model="form.gapCount" :min="0" :step="1" :max="999999" :precision="0" />
              <!-- <el-input v-model="form.gapCount" placeholder="请输入允许溢短数" /> -->
            </el-form-item>
            <el-form-item label="稿件类型" prop="manuscriptType">
              <el-select v-model="form.manuscriptType" placeholder="请选择稿件类型">
                <el-option label="请选择字典生成" value="" />
              </el-select>
            </el-form-item>
            <el-form-item label="执行标准" prop="standard">
              <el-input v-model="form.standard" placeholder="请输入执行标准" />
            </el-form-item>
            <!-- <el-form-item label="订单成本" prop="cost">
              <el-input v-model="form.cost" placeholder="请输入订单成本" />
            </el-form-item> -->
            <el-form-item label="价格(元)" prop="price">
              <el-input-number v-model="form.price" :min="0" :step="1" :max="999999" :precision="2" />
              <!-- <el-input v-model="form.price" placeholder="请输入价格" /> -->
            </el-form-item>
            <!-- <el-form-item label="订单状态">
              <el-radio-group v-model="form.status">
                <el-radio label="1">请选择字典生成</el-radio>
              </el-radio-group>
            </el-form-item> -->
            <el-form-item label="优先级" prop="priority">
              <el-input v-model="form.priority" placeholder="请输入优先级" />
            </el-form-item>
            <el-form-item label="箱子资料" prop="boxInfo">
              <el-input v-model="form.boxInfo" placeholder="请输入箱子资料" />
            </el-form-item>
            <el-form-item label="纸张情况" prop="paperCondition">
              <el-input v-model="form.paperCondition" placeholder="请输入纸张情况" />
            </el-form-item>
            <el-form-item label="纸箱尺寸" prop="cartonSize">
              <el-input v-model="form.cartonSize" placeholder="请输入纸箱尺寸" />
            </el-form-item>
            <el-form-item label="装箱数量" prop="packingQuantity">
              <el-input v-model="form.packingQuantity" placeholder="请输入装箱数量" />
            </el-form-item>
            <el-form-item label="PE袋" prop="peBag">
              <el-input v-model="form.peBag" placeholder="请输入PE袋" />
            </el-form-item>
            <el-form-item label="打包条" prop="packageStrip">
              <el-input v-model="form.packageStrip" placeholder="请输入打包条" />
            </el-form-item>
            <el-form-item label="不干胶" prop="sticker">
              <el-input v-model="form.sticker" placeholder="请输入不干胶" />
            </el-form-item>
            <el-form-item label="包装要求" prop="packageRequirement">
              <el-input v-model="form.packageRequirement" placeholder="请输入包装要求" />
            </el-form-item>
            <el-form-item label="包装备注" prop="packageRemark">
              <el-input v-model="form.packageRemark" placeholder="请输入包装备注" />
            </el-form-item>
            <el-form-item label="印刷米数" prop="printMetres">
              <el-input v-model="form.printMetres" placeholder="请输入印刷米数" />
            </el-form-item>
            <el-form-item label="每卷补管重" prop="pipeWeight">
              <el-input v-model="form.pipeWeight" placeholder="请输入每卷补管重" />
            </el-form-item>
            <el-form-item label="开单人" prop="salesman">
              <el-input v-model="form.salesman" placeholder="请输入开单人" >
                <el-button slot="append" @click="handleUser2Select" icon="el-icon-search"></el-button>
              </el-input>
              <UserSingleSelect ref="user2Select" @onSelected="onUser2Selected"></UserSingleSelect>
            </el-form-item>
            <el-row>
              <el-form-item label="订单描述" prop="orderRemark">
                <el-input type="textarea" style="width: 535px;" v-model="form.orderRemark" placeholder="请输入订单描述" />
              </el-form-item>
              <el-form-item label="业务备注" prop="businessRemark">
                <el-input type="textarea" style="width: 535px;" v-model="form.businessRemark" placeholder="请输入业务备注" />
              </el-form-item>
            </el-row>
            <!-- <el-form-item label="数据行状态(0:正常/1:删除)" prop="delFlag">
              <el-input v-model="form.delFlag" placeholder="请输入数据行状态(0:正常/1:删除)" />
            </el-form-item>
            <el-form-item label="预留字段1" prop="attr1">
              <el-input v-model="form.attr1" placeholder="请输入预留字段1" />
            </el-form-item> -->
          </el-form>
        </el-collapse-item>

        <el-collapse-item title="产品信息" name="3">
          <el-form ref="form.pro" :inline="true" :model="form.pro" :rules="rules" :disabled="viewType == 'VIEW'"
            label-width="120px">
            <el-form-item label="产品编码" prop="itemCode">
              <el-input v-model="form.pro.itemCode" disabled placeholder="请输入产品编码" />
            </el-form-item>
            <el-form-item label="成品尺寸(mm)" prop="itemSize">
              <el-input v-model="itemSize" placeholder="成品尺寸自动生成" disabled />
            </el-form-item>
            <!-- <el-form-item label="工艺路线ID" prop="routeId">
              <el-input v-model="form.pro.routeId" ref="routeId" :disabled="prorouteDisabled" placeholder="请输入工艺路线ID" />
            </el-form-item> -->
            <el-form-item label="工艺路线编号" prop="routeCode">
              <el-input v-model="form.pro.routeCode" :disabled="prorouteDisabled" placeholder="请输入工艺路线编号" />
            </el-form-item>
            <el-form-item label="工艺路线名称" prop="routeName">
              <el-input v-model="form.pro.routeName" :disabled="prorouteDisabled" placeholder="请输入工艺路线名称" />
            </el-form-item>
            <el-form-item label="袋宽(mm)" prop="width">
              <el-input-number v-model="form.pro.width" :min="0" :step="1" :max="999999" :precision="0" />
              <!-- <el-input v-model="form.pro.width" placeholder="请输入袋宽" /> -->
            </el-form-item>
            <el-form-item label="袋高(mm)" prop="hight">
              <el-input-number v-model="form.pro.hight" :min="0" :step="1" :max="999999" :precision="0" />
              <!-- <el-input v-model="form.pro.hight" placeholder="请输入袋高" /> -->
            </el-form-item>
            <el-form-item label="M边(mm)" prop="lateralWidth">
              <el-input-number v-model="form.pro.lateralWidth" :min="0" :step="1" :max="999999" :precision="0" />
              <!-- <el-input v-model="form.pro.lateralWidth" placeholder="请输入M边" /> -->
            </el-form-item>
            <el-form-item label="倒口(mm)" prop="topFold">
              <el-input-number v-model="form.pro.topFold" :min="0" :step="1" :max="999999" :precision="0" />
              <!-- <el-input v-model="form.pro.topFold" placeholder="请输入倒口" /> -->
            </el-form-item>
            <el-form-item label="折底(mm)" prop="bottomFold">
              <el-input-number v-model="form.pro.bottomFold" :min="0" :step="1" :max="999999" :precision="0" />
              <!-- <el-input v-model="form.pro.bottomFold" placeholder="请输入折底" /> -->
            </el-form-item>
            <el-form-item label="工艺边(mm)" prop="craftSide">
              <el-input-number v-model="form.pro.craftSide" :min="0" :step="1" :max="999999" :precision="0" />
              <!-- <el-input v-model="form.pro.craftSide" placeholder="请输入工艺边" /> -->
            </el-form-item>
            <el-form-item label="幅宽(mm)" prop="paperWith">
              <el-input v-model="paperWith" disabled placeholder="幅宽自动生成" />
            </el-form-item>
            <el-form-item label="版周(mm)" prop="paperLong">
              <el-input v-model="paperLong" placeholder="版周自动生成" />
            </el-form-item>
            <el-form-item label="头卡尺寸" prop="headCard">
              <el-input v-model="form.pro.headCard" placeholder="请输入头卡要求" />
            </el-form-item>
            <el-form-item label="底片尺寸" prop="bottomPlateSize">
              <el-input v-model="form.pro.bottomPlateSize" placeholder="请输入底片尺寸" />
            </el-form-item>
            <el-form-item label="底片要求" prop="bottomCard">
              <el-input v-model="form.pro.bottomCard" placeholder="请输入底卡要求" />
            </el-form-item>
            <el-form-item label="绳子颜色" prop="ropeColor">
              <el-input v-model="form.pro.ropeColor" placeholder="请输入绳子颜色" />
            </el-form-item>
            <el-form-item label="绳子长度" prop="ropeLength">
              <el-input v-model="form.pro.ropeLength" placeholder="请输入绳子长度" />
            </el-form-item>
            <el-form-item label="绳子要求" prop="ropeRequirement">
              <el-input v-model="form.pro.ropeRequirement" placeholder="请输入绳子要求" />
            </el-form-item>
            <el-form-item label="孔芯孔距" prop="holeCoreSpacing">
              <el-input v-model="form.pro.holeCoreSpacing" placeholder="请输入孔芯孔距" />
            </el-form-item>
            <el-form-item label="制袋特别说明" prop="bagMakingInstructions">
              <el-input v-model="form.pro.bagMakingInstructions" placeholder="请输入制袋特别说明" />
            </el-form-item>

            <el-form-item label="制袋作业机台" prop="bagMachineryId">
              <!-- <el-input v-model="form.pro.bagMachineryId" placeholder="请输入制袋设备ID" /> -->
              <el-input v-model="form.pro.bagMachineryName" disabled placeholder="请选择设备" >
                <el-button slot="append" icon="el-icon-search" @click="handleMachinerySelect"></el-button>
              </el-input>
              <MachinerySelect ref="machinerySelect" @onSelected="onMachinerySelect"></MachinerySelect>
            </el-form-item>
            <!-- <el-form-item label="制袋设备类型名称" prop="bagMachineryName">
              <el-input v-model="form.pro.bagMachineryName" placeholder="请输入制袋设备类型名称" />
            </el-form-item> -->
            <el-form-item label="主材料" prop="paper">
              <el-select v-model="form.mdItem.paper" placeholder="请选择主材料" filterable>
                <el-option v-for="item in paperList" :key="item.itemId" :label="item.itemName" :value="item.itemId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="纸张实际克重" prop="paperActualWeight">
              <!-- <el-input-number v-model="form.pro.paperActualWeight" :min="0" :step="1" :max="999999" :precision="0" /> -->
              <el-input type="number" v-model="form.pro.paperActualWeight" placeholder="请输入纸张实际克重" />
            </el-form-item>
            <el-form-item label="贴片材质" prop="paster">
              <el-select v-model="form.mdItem.paster" placeholder="请选择贴片材料" filterable >
                <el-option v-for="item in pasterList" :key="item.itemId" :label="item.itemName" :value="item.itemId">
                </el-option>
              </el-select>
              </el-select>
            </el-form-item>
            <el-form-item label="手挽" prop="handle">
              <el-select v-model="form.mdItem.handle" placeholder="请选择手挽" filterable >
                <el-option v-for="item in handleList" :key="item.itemId" :label="item.itemName" :value="item.itemId">
                </el-option>
              </el-select>
              </el-select>
            </el-form-item>
            <el-form-item label="圆/扁绳纸张" prop="ropePaper">
              <el-select v-model="form.mdItem.ropePaper" placeholder="请选择圆/扁绳纸张" filterable >
                <el-option v-for="item in ropePaperList" :key="item.itemId" :label="item.itemName" :value="item.itemId">
                </el-option>
              </el-select>
              </el-select>
            </el-form-item>
            <el-form-item label="绳子" prop="rope">
              <el-select v-model="form.mdItem.rope" placeholder="请选择绳子" filterable >
                <el-option v-for="item in ropeList" :key="item.itemId" :label="item.itemName" :value="item.itemId">
                </el-option>
              </el-select>
              </el-select>
            </el-form-item>
            <el-form-item label="柳钉" prop="rivets">
              <el-select v-model="form.mdItem.rivets" placeholder="请选择柳钉" filterable >
                <el-option v-for="item in rivetsList" :key="item.itemId" :label="item.itemName" :value="item.itemId">
                </el-option>
              </el-select>
              </el-select>
            </el-form-item>
            <el-form-item label="缎带" prop="ribbon">
              <el-select v-model="form.mdItem.ribbon" placeholder="请选择缎带" filterable >
                <el-option v-for="item in ribbonList" :key="item.itemId" :label="item.itemName" :value="item.itemId">
                </el-option>
              </el-select>
              </el-select>
            </el-form-item>
            <el-form-item label="产品净面积(㎡)" prop="area">
              <el-input v-model="area" disabled placeholder="产品净面积自动生成" />
            </el-form-item>
            <el-form-item label="产品克重(g)" prop="weight">
              <el-input v-model="weight" disabled placeholder="产品克重自动生成" />
            </el-form-item>
            <!-- <el-form-item label="数据行状态(0:正常/1:删除)" prop="delFlag">
              <el-input v-model="form.pro.delFlag" placeholder="请输入数据行状态(0:正常/1:删除)" />
            </el-form-item>
            <el-form-item label="预留字段1" prop="attr1">
              <el-input v-model="form.pro.attr1" placeholder="请输入预留字段1" />
            </el-form-item>-->
            <el-row :span="24">
              <el-col :push="10">
                <el-form-item label="纸张价格(元)" prop="price">
                  <el-input v-model="price" placeholder="请输入公斤单价" />
                </el-form-item>
                <el-form-item label="订单数量(个)" prop="count">
                  <el-input v-model="count" placeholder="请输入数量" />
                </el-form-item>
                <el-button @click="offer">报价</el-button>
              </el-col>

            </el-row>
          </el-form>
        </el-collapse-item>
        <el-collapse-item title="印刷信息" name="2">
          <el-form ref="form.pro" :inline="true" :model="form.pro" :rules="rules" :disabled="viewType == 'VIEW'"
            label-width="120px">
            <el-form-item label="模数" prop="modulus">
              <el-input v-model="form.pro.modulus" placeholder="请输入模数" />
            </el-form-item>
            <el-form-item label="印刷类型" prop="printingMethod">
              <el-input v-model="form.pro.printingMethod" placeholder="请输入印刷类型" />
            </el-form-item>
              <el-form-item label="印刷跟色" prop="printingColor">
                <el-input v-model="form.pro.printingColor" placeholder="请输入印刷跟色" />
              </el-form-item>
              <el-form-item label="袋面印刷色" prop="frontPrintColor">
                <!-- <el-input v-model="form.pro.frontPrintColor" placeholder="请输入袋面印刷色" /> -->
                <el-select
                    v-model="form.pro.frontPrintColor"
                    multiple
                    filterable
                    allow-create
                    default-first-option
                    placeholder="请输入袋面印刷色">
                    <!-- <el-option
                      key="key"
                      label="item.label"
                      value="item.value">
                    </el-option> -->
                  </el-select>
              </el-form-item>
              <el-form-item label="袋内印刷色" prop="backPrintColor">
                <!-- <el-input v-model="form.pro.backPrintColor" placeholder="请输入袋内印刷色" /> -->
                <el-select
                    v-model="form.pro.backPrintColor"
                    multiple
                    filterable
                    allow-create
                    default-first-option
                    placeholder="请输入袋内印刷色">
                  </el-select>
              </el-form-item>
              <el-form-item label="印刷备注" prop="printRemark">
                <el-input type="textarea" style="width: 535px;" v-model="form.pro.printRemark" placeholder="请输入印刷备注" />
              </el-form-item>
              <el-row>
                <el-form-item label="烫金类型" prop="goldStampingType">
                  <el-input v-model="form.pro.goldStampingType" placeholder="请输入烫金类型" />
                  <!-- <el-select v-model="form.goldStampingType" placeholder="请选择烫金类型">
                    <el-option label="请选择字典生成" value="" />
                  </el-select> -->
                </el-form-item>
                <el-form-item label="烫金说明" prop="goldStampingNotes">
                  <el-input type="textarea" style="width: 535px;" v-model="form.pro.goldStampingNotes" placeholder="请输入烫金说明" />
                </el-form-item>
              </el-row>

              <el-form-item label="特殊加工" prop="specialProcess">
                <el-input v-model="form.pro.specialProcess" placeholder="请输入特殊加工" />
              </el-form-item>
              <el-form-item label="特殊说明" prop="specialNotes">
                <el-input type="textarea" style="width: 535px;" v-model="form.pro.specialNotes" placeholder="请输入特殊说明" />
              </el-form-item>
              <el-row>
                <el-form-item label="单张分切规格" prop="sheetCuttingSpecification">
                  <el-input v-model="form.pro.sheetCuttingSpecification" placeholder="请输入单张分切规格" />
                </el-form-item>
                <el-form-item label="分切备注" prop="cuttingRemark">
                  <el-input v-model="form.pro.cuttingRemark" placeholder="请输入分切备注" />
                </el-form-item>
              </el-row>

            </el-form>

        </el-collapse-item>
        <el-collapse-item title="工序信息" name="4">
          <el-form ref="processSelectList" :inline="true" :model="form.pro" :rules="rules"
            :disabled="viewType == 'VIEW'" label-width="88px">
            <el-row>
              <el-form-item label="工艺流程" prop="routeId">
                <el-select v-model="proroute" placeholder="工艺流程" @change="getRouteprocessList">
                  <el-option v-for="item in prorouteList" :label="item.routeCode + '-' + item.routeName"
                    :value="item.routeId" />
                </el-select>
              </el-form-item>
            </el-row>
            <el-row>
              <el-form-item v-for="(process, index) in processSelectList" prop="processId">
                <el-select v-model="process.processData" :placeholder="'工序' + (index + 1)" clearable  @change="resetProroute" filterable>
                  <el-option v-for="item in processList" :label="item.processName"
                    :value="item.processId + '_' + item.processName" />
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-button @click="addProcess">添加工序</el-button>
              </el-form-item>
            </el-row>
            <el-row :span="24">
              <el-col :span="2">
                <b>工艺流程图：</b>
              </el-col>
              <el-col :span="20">
                <el-steps :active="20" align-center>
                  <el-step v-for="(process, index) in processFilterList" :title="process.processData.split('_')[1]">
                  </el-step>
                </el-steps>
                <!-- <b>
                  <span v-for="(process, index) in processSelectList">{{process.processData != null ? process.processData.split('_')[1] + '--' : null}}</span>
                  </b> -->
              </el-col>
            </el-row>

          </el-form>
        </el-collapse-item>
      </el-collapse>

      <div slot="footer" class="dialog-footer">
        <el-button @click="resetBtn" v-if="viewType != 'VIEW'">清 空</el-button>
        <el-button type="primary" @click="submitForm" v-if="viewType != 'VIEW'">确 定</el-button>
        <el-button @click="cancel">{{viewType != 'VIEW' ? "取 消" : "返回"}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listOrder,
    getOrder,
    delOrder,
    addOrder,
    updateOrder,
    updateOrderStatus,
    approved
  } from "@/api/mes/md/order";
  import {
    listProcess
  } from "@/api/mes/pro/process";
  import {
    listProroute
  } from "@/api/mes/pro/proroute";
  import {
    listRouteprocess
  } from "@/api/mes/pro/routeprocess";
  import {
    listMdItem
  } from "@/api/mes/md/mdItem";
  import {
    listItemType
  } from "@/api/mes/md/itemtype";
  import {
    listRoutetypeByItemTypeId
  } from "@/api/mes/pro/routetype"
  import ClientSelect from "@/components/clientSelect/single.vue";
  import ItemSelect from "@/components/itemSelect/single.vue";
  import UserSingleSelect from "@/components/userSelect/single.vue"
  import MachinerySelect from "@/components/machinerySelect/single.vue";

  export default {
    name: "Order",
    components: {
      ClientSelect,
      ItemSelect,
      UserSingleSelect,
      MachinerySelect
    },
    dicts: ['mes_md_order_status', 'mes_order_type', 'mes_review_type'],
    data() {
      return {
        userName: undefined,
        userId: undefined,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 业务订单表格数据
        orderList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 预留字段1时间范围
        daterangeOrderDate: [],
        // 预留字段1时间范围
        daterangeRequestDate: [],
        // 新增订单弹出框信息重置标识
        resetFormFlag: true,
        // 弹窗类型
        viewType: "",
        // 物料分类列表数据
        itemTypeList: [],
        // 物料列表数据
        itemList: [],
        // 工艺流程输入框状态
        prorouteDisabled: false,
        // 工艺流程
        proroute: null,
        // 工艺流程列表
        prorouteList: [],
        // 选中历史订单
        selectOrderId: null,
        // 工序数据集合
        processList: [{
            processId: 1,
            processName: "分切"
          }, {
            processId: 2,
            processName: "烫金"
          },
          {
            processId: 3,
            processName: "外发胶印"
          }, {
            processId: 4,
            processName: "包装"
          },
        ],
        // 工序下拉集合
        processSelectList: [{
            processNum: 1,
            processData: null
          }, {
            processNum: 2,
            processData: null
          },
          {
            processNum: 3,
            processData: null
          }, {
            processNum: 4,
            processData: null
          },
          {
            processNum: 5,
            processData: null
          }, {
            processNum: 6,
            processData: null
          },
          {
            processNum: 7,
            processData: null
          }, {
            processNum: 8,
            processData: null
          },
          {
            processNum: 9,
            processData: null
          }, {
            processNum: 10,
            processData: null
          },
          {
            processNum: 11,
            processData: null
          }, {
            processNum: 12,
            processData: null
          },
        ],
        // 只看我
        checked: false,
        // 纸张价格
        price: null,
        // 订单数量
        count: null,
        // 面板id
        activeNames: ["1"],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          orderCode: null,
          orderType: null,
          clientId: null,
          clientCode: null,
          clientName: null,
          itemTypeId: null,
          productId: null,
          productCode: null,
          productName: null,
          orderDate: null,
          requestDate: null,
          orderCount: null,
          stockCount: null,
          quantity: null,
          reviewType: null,
          routeId: null,
          routeCode: null,
          routeName: null,
          feedingPoint: null,
          feedingCount: null,
          paperAmount: null,
          gapCount: null,
          manuscriptType: null,
          standard: null,
          cost: null,
          price: null,
          orderRemark: null,
          businessRemark: null,
          status: null,
          priority: null,
          boxInfo: null,
          salesman: null,
          attr1: null,
        },
        // 表单参数
        form: {
          pro: {},
          mdItem: {}
        },
        // 表单校验
        rules: {
          orderCode: [{
            required: true,
            message: "订单编号不能为空",
            trigger: "blur"
          }],
          clientId: [{
            required: true,
            message: "客户ID不能为空",
            trigger: "blur"
          }],
          clientCode: [{
            required: true,
            message: "客户编码不能为空",
            trigger: "blur"
          }],
          clientName: [{
            required: true,
            message: "客户名称不能为空",
            trigger: "blur"
          }],
          productId: [{
            required: true,
            message: "产品ID不能为空",
            trigger: "blur",
          }],
          productCode: [{
            required: true,
            message: "产品编号不能为空",
            trigger: "blur"
          }],
          productName: [{
            required: true,
            message: "产品名称不能为空",
            trigger: "blur"
          }],
          orderDate: [{
            required: true,
            message: "下单日期不能为空",
            trigger: "blur",
          }],
          requestDate: [{
            required: true,
            message: "交货日期不能为空",
            trigger: "blur"
          }],
          orderCount: [{
            required: true,
            message: "订单数量不能为空",
            trigger: "blur",
          }],
          routeCode: [{
            required: true,
            message: "工艺路线编号不能为空",
            trigger: "blur"
          }],
          routeName: [{
            required: true,
            message: "工艺路线名称不能为空",
            trigger: "blur"
          }],
          feedingPoint: [{
            required: true,
            message: "投料点不能为空",
            trigger: "blur"
          }],
          feedingCount: [{
            required: true,
            message: "投料数量不能为空",
            trigger: "blur"
          }],
          status: [{
            required: true,
            message: "订单状态不能为空",
            trigger: "blur"
          }],
          salesman: [{
            required: true,
            message: "开单人不能为空",
            trigger: "blur"
          }],
          itemTypeId: [{
            required: true,
            message: "产品分类不能为空",
            trigger: "blur"
          }],
          'mdItem.paper': [{
            required: true,
            message: "主材料不能为空",
            trigger: "blur"
          }],
          paperActualWeight: [{
            required: true,
            message: "纸张实际克重不能为空",
            trigger: "blur"
          }],
          itemSize: [{
            required: true,
            message: "成品尺寸不能为空",
            trigger: "blur"
          }],
          hight: [{
            required: true,
            message: "袋高不能为空",
            trigger: "blur"
          }],
          lateralWidth: [{
            required: true,
            message: "M边不能为空",
            trigger: "blur"
          }],
          width: [{
            required: true,
            message: "袋宽不能为空",
            trigger: "blur"
          }],
          paperLong: [{
            required: true,
            message: "版周不能为空",
            trigger: "blur"
          }],
        }
      };
    },
    created() {
      this.userName = this.$store.state.user.name;
      this.userId = this.$store.state.user.id;
      this.getList();
      this.getProrouteList();
      this.getProcessList();
      this.getMdItemList();
      this.getItemTypeList();
    },
    watch: {
      'form.productCode'(newVal, oldVal) {
        this.form.pro.itemCode = newVal;
      },
      'form.productId'(newVal, oldVal) {
        if (oldVal != null) {
          this.form.pro.itemId = null;
        }
      }
    },
    computed: {
      // 产品类别
      itemTypeName() {
        return function(id) {
          let list = this.itemTypeList.filter(item => item.itemTypeId == id)
          return list.length > 0 ? list[0].itemTypeName : "";
        }
      },
      // 投产量
      feedingCount: function() {
        this.form.feedingCount = (parseFloat(this.form.orderCount) * (100 + parseFloat(this.form.feedingPoint)) /
          100) - parseFloat(this.form.stockCount);
          if (this.form.feedingCount && parseFloat(this.form.feedingCount) > 0) {
            this.form.quantity = this.form.feedingCount;
          }
        return this.form.feedingCount && parseFloat(this.form.feedingCount) > 0 ? this.form.feedingCount : null;
      },
      // 幅宽 =（袋宽+插角）×2+工艺边
      paperWith() {
        this.form.pro.paperWith = (parseFloat(this.form.pro.width) + parseFloat(this.form.pro.lateralWidth)) * 2 + this
          .form.pro.craftSide;
        return this.form.pro.paperWith ? this.form.pro.paperWith : null;
      },
      // 料长 = 袋高+折口+（插角÷2+2）
      paperLong() {
        // return this.form.pro.hight + this.form.pro.topFold + (this.form.pro.lateralWidth / 2 + 2)
        this.form.pro.paperLong = this.form.pro.hight + this.form.pro.topFold + this.form.pro.bottomFold;
        return this.form.pro.paperLong ? this.form.pro.paperLong : null;
      },
      // 产品面积 = 料长 * 幅宽
      area() {
        this.form.pro.area = (this.paperWith * this.paperLong / 1000000).toFixed(4);
        return this.form.pro.area ? this.form.pro.area : null;
      },
      // 产品克重
      weight() {
        if (this.form.mdItem.paper) {
          let list = this.paperList.filter(item => item.itemId == this.form.mdItem.paper)
          this.form.pro.weight = (this.area * parseFloat(list[0].itemName)).toFixed(2);
          return this.form.pro.weight ? this.form.pro.weight : null;
        }

      },
      // 工艺下拉框过滤空值
      processFilterList() {
        let list = this.processSelectList.filter(item => item.processData != null && item.processData != "");
        this.form.prorouteList = list;
        return list;
      },
      // 主材料列表数据过滤
      paperList() {
        return this.itemList.filter(item => item.itemTypeCode == "ITEM_TYPE_0108")
      },
      // 贴片材料列表数据过滤
      pasterList() {
        return this.itemList.filter(item => item.itemTypeCode == "ITEM_TYPE_0109")
      },
      // 手挽列表数据过滤
      handleList() {
        return this.itemList.filter(item => item.itemTypeCode == "ITEM_TYPE_0110")
      },
      // 圆/扁绳纸张列表数据过滤
      ropePaperList() {
        return this.itemList.filter(item => item.itemTypeCode == "ITEM_TYPE_0111")
      },
      // 绳子列表数据过滤
      ropeList() {
        return this.itemList.filter(item => item.itemTypeCode == "ITEM_TYPE_0112")
      },
      // 柳钉列表数据过滤
      rivetsList() {
        return this.itemList.filter(item => item.itemTypeCode == "ITEM_TYPE_0113")
      },
      // 缎带列表数据过滤
      ribbonList() {
        return this.itemList.filter(item => item.itemTypeCode == "ITEM_TYPE_0114")
      },
      // 成品尺寸
      itemSize() {
        let size = this.form.pro.width + "+" + this.form.pro.lateralWidth + "x" + this.form.pro.hight + "+" + this.form.pro.bottomFold;
        if (this.form.pro.topFold && this.form.pro.topFold > 0) {
          size = size + "+" + this.form.pro.topFold
        }
        this.form.pro.itemSize = size;
        return size;
      },
      // 订单用纸
      paperAmount() {
        if (this.weight) {
          // 产品克重*数量/1000
          this.form.paperAmount = Math.round(this.weight * this.feedingCount / 1000)
        }
        return this.form.paperAmount;
      },
    },
    methods: {
      /** 查询业务订单列表 */
      getList() {
        this.loading = true;
        this.queryParams.params = {};
        if (null != this.daterangeOrderDate && '' != this.daterangeOrderDate) {
          this.queryParams.params["beginOrderDate"] = this.daterangeOrderDate[0];
          this.queryParams.params["endOrderDate"] = this.daterangeOrderDate[1];
        }
        if (null != this.daterangeRequestDate && '' != this.daterangeRequestDate) {
          this.queryParams.params["beginRequestDate"] = this.daterangeRequestDate[0];
          this.queryParams.params["endRequestDate"] = this.daterangeRequestDate[1];
        }
        listOrder(this.queryParams).then(response => {
          this.orderList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 选择设备
      handleMachinerySelect() {
        this.$refs.machinerySelect.showFlag = true;
      },
      // 选中设备回调
      onMachinerySelect(row) {
        if(row) {
          this.form.pro.bagMachineryId = row.machineryId;
          this.form.pro.bagMachineryName = row.machineryName;
        }

      },
      /** 报表预览 */
      handlePreview(orderId) {
        window.open(`${this.website.reportUrl}/preview?_u=mysql:%25E4%25BD%259C%25E4%25B8%259A%25E5%258D%2595.ureport.xml&order_id=`+orderId)
      },
      //点击人员选择按钮
      handleUser2Select(){
          this.$refs.user2Select.showFlag = true;
      },
      // 开单人选择返回
      onUser2Selected(row){
          this.form.salesmanId = row.userId;
          this.form.salesman = row.nickName;
      },
      // 只看我的订单
      handleCheckboxChange(value) {
        if (value) {
          // console.log("11", this.$store.state.user.name)
          this.queryParams.createBy = this.$store.state.user.name;
          this.getList();
        } else {
          this.queryParams.createBy = null;
          this.getList();
        }
      },
      /** 查询物料分类列表 */
      getItemTypeList() {
        let param = {
          parentTypeId: 201
        }
        listItemType(param).then(response => {
          // var types = this.handleTree(response.data, "itemTypeId","parentTypeId");
          this.itemTypeList = response.data;
        });
      },
      /** 查询物料编码列表 */
      getMdItemList() {
        let param = {
          itemOrProduct: "ITEM"
        }
        listMdItem(param).then(response => {
          this.itemList = response.rows;
        });
      },
      /** 查询工艺路线列表 */
      getProrouteList() {
        listProroute(null).then(response => {
          this.prorouteList = response.rows;
        });
      },
      /** 查询生产工序列表 */
      getProcessList() {
        listProcess(null).then(response => {
          this.processList = response.rows;
        });
      },
      // 查询产品类别关联工艺流程列表
      getRoutetypeListByItemTypeId() {
        let param = {
          itemTypeId: this.form.itemTypeId
        };
        listRoutetypeByItemTypeId(param).then(response => {
          this.prorouteList = response.rows;
        });
      },
      /** 查询工艺组成列表 */
      getRouteprocessList() {
        this.prorouteDisabled = true;
        if (this.proroute != null) {
          this.form.pro.routeId = this.proroute;
          let list = this.prorouteList.filter(item => item.routeId == this.proroute);
          if (list.length > 0) {
            this.form.pro.routeCode = list[0].routeCode;
            this.form.pro.routeName = list[0].routeName;
          }
          this.form.prorouteList = [];
        }
        let param = {
          routeId: this.proroute
        }
        listRouteprocess(param).then(response => {
          let routeprocessList = response.rows;
          for (var i = 0; i < routeprocessList.length; i++) {
            this.processSelectList[i].processData = routeprocessList[i].processId + "_" + routeprocessList[i]
              .processName;
          }
          for (var i = routeprocessList.length; i < this.processSelectList.length; i++) {
            this.processSelectList[i].processData = null;
          }
        });
      },
      // 填充历史订单数据到添加表单
      fillForm() {
        this.resetFormFlag = true;
        this.reset();
        getOrder(this.selectOrderId).then(response => {
          this.form = response.data;
          this.form.orderId = null;
          this.form.status = null;
          this.form.delFlag = null;
          this.form.attr1 = null;
          this.form.updateBy = null;
          this.form.updateTime = null;
          this.form.orderDate = null;
          this.form.requestDate = null;
          // this.form.pro.itemId = null;
          // this.form.pro.routeId = null;
          this.proroute = this.form.pro.routeId;
          this.getRouteprocessList();
        });
      },
      // 只读查看订单详情对话框
      openView(row) {
        this.resetFormFlag = true;
        this.reset();
        const orderId = row.orderId || this.ids
        getOrder(orderId).then(response => {
          this.form = response.data;
          this.proroute = this.form.pro.routeId;
          this.getRouteprocessList();
          this.open = true;
          this.title = "查看业务订单";
          this.viewType = "VIEW"
        });
      },
      //重置工艺流程下拉框
      resetProroute() {
        if (this.proroute != null) {
          this.proroute = null;
          this.prorouteDisabled = !this.prorouteDisabled;
          this.form.pro.routeCode = null;
          this.form.pro.routeName = null;
          this.form.prorouteList = this.processFilterList;
          this.form.pro.routeId = null;
          this.$message('开始自定义工艺流程，请记得填写工艺路线编号及名称');
        }
      },
      // 报价
      offer() {
        if (this.weight && this.price && this.count) {
          let money = this.weight * this.price * this.count / 1000;
          this.$alert("纸张价格：" + money.toFixed(2) + "元", '订单报价', {
            confirmButtonText: '确定',
            callback: action => {}
          });
        } else {
          this.$message('请完善产品规格');
        }

      },
      // 添加工序
      addProcess() {
        this.processSelectList.push({
          processNum: this.processSelectList.length + 1,
          processData: null
        })
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 清空按钮
      resetBtn() {
        this.resetFormFlag = true;
        this.selectOrderId = null;
        this.reset();
      },
      // 表单重置
      reset() {
        if (this.resetFormFlag) {
          this.form = {
            orderId: null,
            orderCode: null,
            orderType: null,
            clientId: null,
            clientCode: null,
            clientName: null,
            itemTypeId: null,
            productId: null,
            productCode: null,
            productName: null,
            orderDate: null,
            requestDate: null,
            orderCount: null,
            stockCount: null,
            quantity: null,
            reviewType: null,
            routeId: null,
            routeCode: null,
            routeName: null,
            feedingPoint: null,
            feedingCount: null,
            paperAmount: null,
            gapCount: null,
            manuscriptType: null,
            standard: null,
            cost: null,
            price: null,
            orderRemark: null,
            businessRemark: null,
            status: "CREATE",
            priority: null,
            boxInfo: null,
            salesman: null,
            delFlag: null,
            attr1: null,
            createBy: null,
            createTime: null,
            updateBy: null,
            updateTime: null,
            paperCondition: null,
            cartonSize: null,
            packingQuantity: null,
            peBag: null,
            packageStrip: null,
            sticker: null,
            packageRequirement: null,
            packageRemark: null,
            printMetres: null,
            pipeWeight: null,
            pro: {
              itemId: null,
              itemCode: null,
              itemSize: null,
              routeId: null,
              routeCode: null,
              routeName: null,
              width: null,
              hight: null,
              lateralWidth: null,
              topFold: null,
              bottomFold: null,
              craftSide: null,
              paperWith: null,
              paperLong: null,
              printingMethod: null,
              headCard: null,
              bottomCard: null,
              area: null,
              weight: null,
              printingColor: [],
              backPrintColor: [],
              printingColor: null,
              frontPrintColor: null,
              printRemark: null,
              goldStampingType: null,
              goldStampingNotes: null,
              specialProcess: null,
              specialNotes: null,
              sheetCuttingSpecification: null,
              cuttingRemark: null,
              ropeColor: null,
              ropeLength: null,
              ropeRequirement: null,
              holeCoreSpacing: null,
              bottomPlateSize: null,
              bagMakingInstructions: null,
              modulus: null,
              bagMachineryId: null,
              bagMachineryName: null,
              paperActualWeight: null
            },
            mdItem: {
              paper: null,
              paster: null,
              handle: null,
              ropePaper: null,
              rope: null,
              rivets: null,
              ribbon: null,
            }
          };
          this.processSelectList = [{
              processNum: 1,
              processData: null
            }, {
              processNum: 2,
              processData: null
            },
            {
              processNum: 3,
              processData: null
            }, {
              processNum: 4,
              processData: null
            },
            {
              processNum: 5,
              processData: null
            }, {
              processNum: 6,
              processData: null
            },
            {
              processNum: 7,
              processData: null
            }, {
              processNum: 8,
              processData: null
            },
            {
              processNum: 9,
              processData: null
            }, {
              processNum: 10,
              processData: null
            },
            {
              processNum: 11,
              processData: null
            }, {
              processNum: 12,
              processData: null
            },
          ];
          this.resetForm("form");
          this.resetFormFlag = false;
        }
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.daterangeOrderDate = [];
        this.daterangeRequestDate = [];
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.orderId)
        this.single = selection.length !== 1 || selection.filter(item => item.status != "CREATE").length !== 0;
        this.multiple = !selection.length || selection.filter(item => item.status != "CREATE").length !== 0;
      },
      /** 详情展示 */
      handleView(row) {
        getOrder(row.orderId).then(response => {
          this.form = response.data;
          this.proroute = this.form.pro.routeId;
          this.form.pro.backPrintColor = (this.form.pro.backPrintColor != null && this.form.pro.backPrintColor != "" ) ? this.form.pro.backPrintColor.split(",") : [];
          this.form.pro.frontPrintColor = (this.form.pro.frontPrintColor != null && this.form.pro.frontPrintColor != "") ? this.form.pro.frontPrintColor.split(",") : [];
          this.getRouteprocessList();
          this.open = true;
          this.title = "业务订单详情";
          this.viewType = "VIEW"
        });
      },
      /** 新增按钮操作 */
      handleAdd() {
        if (this.viewType != "ADD") {
          this.resetFormFlag = true;
        }
        this.reset();
        this.open = true;
        this.resetFormFlag = false;
        this.title = "添加业务订单";
        this.viewType = "ADD"
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.resetFormFlag = true;
        this.prorouteDisabled = true;
        this.reset();
        const orderId = row.orderId || this.ids
        getOrder(orderId).then(response => {
          this.form = response.data;
          this.proroute = this.form.pro.routeId;
          this.form.pro.backPrintColor = (this.form.pro.backPrintColor != null && this.form.pro.backPrintColor != "" ) ? this.form.pro.backPrintColor.split(",") : [];
          this.form.pro.frontPrintColor = (this.form.pro.frontPrintColor != null && this.form.pro.frontPrintColor != "") ? this.form.pro.frontPrintColor.split(",") : [];
          this.getRouteprocessList();
          this.open = true;
          this.title = "修改业务订单";
          this.viewType = "UPDATE"
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form","form.pro"].validate(valid => {
          if (valid) {
            if (this.processFilterList.length < 1) {
              this.$modal.msgError("工艺流程不能为空");
              return;
            }
            if (!this.form.mdItem.paper) {
              this.$modal.msgError("主材料不能为空");
              return;
            }
            this.form.prorouteList = this.processFilterList;
            this.form.pro.backPrintColor = (this.form.pro.backPrintColor && this.form.pro.backPrintColor.length>0) ? this.form.pro.backPrintColor.join(",") : null;
            this.form.pro.frontPrintColor = (this.form.pro.frontPrintColor && this.form.pro.frontPrintColor.length>0) ? this.form.pro.frontPrintColor.join(",") : null;
            if (this.form.orderId != null) {
              updateOrder(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.resetFormFlag = true;
                this.getList();
                this.getProrouteList();
              });
            } else {
              addOrder(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.resetFormFlag = true;
                this.getList();
                this.getProrouteList();
              });

            }
          }
        });
      },
      /** 驳回订单，改变订单状态 */
      handleOrderStatus(row, status) {
        const orderId = row.orderId || this.ids[0]
        let param = {
          "status": status,
          "orderId": orderId,
          "orderCode": row.orderCode
        };
        this.$confirm('是否修改当前订单状态', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          updateOrderStatus(param).then(response => {
            this.$modal.msgSuccess("订单修改成功");
            // this.open = false;
            // this.resetFormFlag = true;
            this.getList();
            this.getProrouteList();
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });

      },
      /** 订单审批 */
      handleOrderApproved(row) {
        this.$confirm('确认订单' + row.orderCode + '无误', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          const orderId = row.orderId || this.ids
          approved(orderId).then(response => {
            // console.log("订单审批", response)
            this.$modal.msgSuccess(response.msg);
            this.getList();
            this.getProrouteList();
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });

      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const orderIds = row.orderId || this.ids;
        this.$modal.confirm('是否确认删除业务订单编号为"' + orderIds + '"的数据项？').then(function() {
          return delOrder(orderIds);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('mes/md/order/export', {
          ...this.queryParams
        }, `order_${new Date().getTime()}.xlsx`)
      },
      /** 导出评审表按钮操作 */
      handleExportReview(row) {
        const orderId = row.orderId || this.ids[0]
        // let url = "http://localhost" + process.env.VUE_APP_BASE_API + "mes/md/order/exportReview"
        // window.open("https://view.officeapps.live.com/op/view.aspx?src=" + url, "_blank");
        this.download('mes/md/order/exportReview', {
          orderId: orderId
        }, `review_${new Date().getTime()}.xlsx`)
      },
      // 打开产品弹出框
      handleSelectProduct() {
        this.$refs.itemSelect.showFlag = true;
      },
      //物料选择弹出框
      onItemSelected(obj) {
        if (obj != undefined && obj != null) {
          this.form.productId = obj.itemId;
          this.form.productCode = obj.itemCode;
          this.form.productName = obj.itemName;
          this.form.pro.itemId = obj.itemId;
          // this.form.productSpc = obj.specification;
          // let spcList = []
          // for (var i = 0; i < obj.specification.length; i++) {
          //   spcList.push({attrName: obj.specification[i].attrName,attrValue: obj.specification[i].attrValue})
          // }
          // this.form.productSpc = JSON.stringify(spcList);
          // this.form.unitOfMeasure = obj.unitOfMeasure;
        }
      },
      // 打开客户选择弹出框
      handleSelectClient() {
        this.$refs.clientSelect.showFlag = true;
      },
      // 客户选择弹出框回调
      onClientSelected(obj) {
        if (obj != undefined && obj != null) {
          this.$set(this.form, 'clientId', obj.clientId);
          this.$set(this.form, 'clientCode', obj.clientCode);
          this.$set(this.form, 'clientName', obj.clientName);
          // this.form.clientId = obj.clientId;
          // this.form.clientCode = obj.clientCode;
          // this.form.clientName = obj.clientName;
        }
      },
    }
  };
</script>
<style scoped>
  .el-select,
  .el-date-editor {
    width: 200px;
  }

  .el-date-editor /deep/ .el-input {
    width: 200px;
  }


  .is-disabled /deep/ .el-input__inner {
    color: #1d1f23;
  }
</style>
